package com.huangpeng.designmodel.singleton;

/**
 * @Author hp
 * @Title 枚举 --Java粑粑强烈推荐使用
 * @Package
 * @Date 2022/1/19 10:47
 * @Description
 * @Version 1.0
 */
public class SingletonEnum {
    public static void main(String[] args) {
        System.out.println(SingletonEnumTest.INSTANCE==SingletonEnumTest.INSTANCE);
        SingletonEnumTest m1 = SingletonEnumTest.INSTANCE;
        SingletonEnumTest m2 = SingletonEnumTest.INSTANCE;
        m1.say();
        m1.say();
        System.out.println(m2.getI());
    }
}

enum SingletonEnumTest{//枚举类型
    INSTANCE;
    private int i=0;
    public void say(){
        System.out.println("Hello World !!!");
        i++;
    }
    public int getI() {
        return i;
    }
}
